package com.zsw.customer1c;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RetryRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableDiscoveryClient
@EnableHystrix
@Configuration
public class Customer1cApplication {

    public static void main(String[] args) {
        SpringApplication.run(Customer1cApplication.class, args);
    }

    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate();
    }


    @Bean
    public IRule myRule(){
        return new RetryRule();// 重试策略 ,一个服务挂了,调用失败N次后不再调用失败的服务，重试其它可用的服务（服务都为健康状态下是为轮询算法）
//        return new RoundRobinRule();//轮询算法，默认
//          return new RandomRule(); //随机算法
//        return new WeightedResponseTimeRule();//权重
    }
}
